﻿
@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<style>
    .form .formValue input.form-control {
        height: 34px;
        line-height: 34px;
    }

    .form-control {
        padding: 0px;
    }

    .autocomplete-suggestions {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        border: 1px solid #999;
        background: #FFF;
        cursor: default;
        overflow: auto;
        -webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        -moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-no-suggestion {
        padding: 2px 5px;
    }

    .Table {
        width: 100%;
        margin: 0px;
        padding: 0px;
        border-collapse: collapse;
        border-width: 3px 1px 1px;
        table-layout: fixed;
    }
</style>
<script>
    var resultData;
    //var workFlowId = $.request("workFlowId");
    var keyValue = $.request("keyValue");
    // var workFlowName = $.request("workFlowName");

    $(function () {
        GetInit();
        $("#F_OpreationUserId").select2({ multiple: true });
        $("#F_OpreationType").select2({ multiple: true });
        $("#F_MessageSend").select2({ multiple: true });
        $("#F_CcUserId").select2({ multiple: true });
        initEntity();
        //gridList(F_ClientId);
    });

    function initEntity() {
        $.ajax({
            url: "/WorkFlowSetting/FlowManage/GetWorkFlowByIdJson?keyValue=" + keyValue + "",
            dataType: "json",
            async: false,
            success: function (data) {
                if (data != null) {
                    $("#F_WorkFlowName").val(data["F_WorkFlowName"]);
                    $("#F_WorkFormId").val(data["F_WorkFormId"]);
                    $("#F_CreatorUserId").val(data["F_CreatorUserId"]);
                    $("#F_CreatorTime").val(data["F_CreatorTime"]);
                    $("#F_LastModifyUserId").val(data["F_LastModifyUserId"]);
                    $("#F_LastModifyTime").val(data["F_LastModifyTime"]);

                }
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }

    function InitControl() {

        var F_MessageSend = resultData.F_MessageSend;
        for (var i = 0; i < F_MessageSend.length; i++) {
            $("#F_MessageSend").append("<option value='" + F_MessageSend[i].F_ItemCode + "'>" + F_MessageSend[i].F_ItemName + "</option>");
        }

        var F_OpreationStrategy = resultData.F_OpreationStrategy;
        for (var i = 0; i < F_OpreationStrategy.length; i++) {
            $("#F_OpreationStrategy").append("<option value='" + F_OpreationStrategy[i].F_ItemCode + "'>" + F_OpreationStrategy[i].F_ItemName + "</option>");
        }

        var F_OpreationType = resultData.F_OpreationType;
        for (var i = 0; i < F_OpreationType.length; i++) {
            $("#F_OpreationType").append("<option value='" + F_OpreationType[i].F_ItemCode + "'>" + F_OpreationType[i].F_ItemName + "</option>");
        }

        var F_ReturnStrategy = resultData.F_ReturnStrategy;
        for (var i = 0; i < F_ReturnStrategy.length; i++) {
            $("#F_ReturnStrategy").append("<option value='" + F_ReturnStrategy[i].F_ItemCode + "'>" + F_ReturnStrategy[i].F_ItemName + "</option>");
        }

        var F_ReturnType = resultData.F_ReturnType;
        for (var i = 0; i < F_ReturnType.length; i++) {
            $("#F_ReturnType").append("<option value='" + F_ReturnType[i].F_ItemCode + "'>" + F_ReturnType[i].F_ItemName + "</option>");
        }

        var F_TimeOutOpreation = resultData.F_TimeOutOpreation;
        for (var i = 0; i < F_TimeOutOpreation.length; i++) {
            $("#F_TimeOutOpreation").append("<option value='" + F_TimeOutOpreation[i].F_ItemCode + "'>" + F_TimeOutOpreation[i].F_ItemName + "</option>");
        }

        var F_TimeOutTip = resultData.F_TimeOutTip;
        for (var i = 0; i < F_TimeOutOpreation.length; i++) {
            $("#F_TimeOutTip").append("<option value='" + F_TimeOutTip[i].F_ItemCode + "'>" + F_TimeOutTip[i].F_ItemName + "</option>");
        }

        var F_Users = resultData.F_Users;
        for (var i = 0; i < F_Users.length; i++) {
            $("#F_CcUserId").append("<option value='" + F_Users[i].F_Id + "'>" + F_Users[i].F_Account + "</option>");
            $("#F_OpreationUserId").append("<option value='" + F_Users[i].F_Id + "'>" + F_Users[i].F_Account + "</option>");
        }


        //var F_ActivityType = resultData.F_ActivityType;
        //for (var i = 0; i < F_ActivityType.length; i++) {
        //    $("#F_ActivityType").append("<option value='" + F_ActivityType[i].F_ItemCode + "'>" + F_ActivityType[i].F_ItemName + "</option>");
        //}

        //var F_ActivityCityId = resultData.F_ActivityCityId;
        //for (var i = 0; i < F_ActivityCityId.length; i++) {
        //    $("#F_ActivityCityId").append("<option value='" + F_ActivityCityId[i].F_ItemCode + "'>" + F_ActivityCityId[i].F_ItemName + "</option>");
        //}

        //var F_SiteType = resultData.F_SiteType;
        //for (var i = 0; i < F_SiteType.length; i++) {
        //    $("#F_SiteType").append("<option value='" + F_SiteType[i].F_ItemCode + "'>" + F_SiteType[i].F_ItemName + "</option>");
        //}

        //var F_CityId = resultData.F_CityId;
        //for (var i = 0; i < F_CityId.length; i++) {
        //    $("#F_CityId").append("<option value='" + F_CityId[i].F_Id + "'>" + F_CityId[i].F_ItemName + "</option>");
        //}

        //var F_AreaId = resultData.F_AreaId;
        //for (var i = 0; i < F_AreaId.length; i++) {
        //    $("#F_AreaId").append("<option value='" + F_AreaId[i].F_ItemCode + "'>" + F_AreaId[i].F_ItemName + "</option>");
        //}

        //var Clients = [];
        //var SiteClients = resultData.SiteClients;
        //for (var i = 0; i < SiteClients.length; i++) {
        //    Clients.push({ value: SiteClients[i].F_ClientName, data: SiteClients[i].F_Id });
        //}

        //$("#F_ClientName").autocomplete({
        //    lookup: Clients,
        //    onSelect: function (suggestion) {
        //        $("#hd_ClientName").val(suggestion.data);
        //        for (var i = 0; i < resultData.SiteClients.length; i++) {
        //            if (suggestion.data == resultData.SiteClients[i].F_Id) {
        //                $("#F_CompanyType").val(resultData.SiteClients[i].F_CompanyType);
        //                $("#F_ClientLevel").val(resultData.SiteClients[i].F_ClientLevel);
        //                $("#F_CityId").val(resultData.SiteClients[i].F_CityId);
        //                ChangeCityData();
        //                $("#F_Address").val(resultData.SiteClients[i].F_Address);
        //                $("#F_IndustryId").val(resultData.SiteClients[i].F_IndustryId);
        //            }
        //        }
        //        ProjectChange(suggestion.data);
        //        ReloadGridListRecord(suggestion.data);
        //    }
        //});

        //$("#F_MappingId").autocomplete({
        //    lookup: Clients,
        //    onSelect: function (suggestion) {
        //        $("#hd_F_MappingId").val(suggestion.data);
        //    }
        //});
    }

    //function ReloadGridListRecord(F_ClientId) {
    //    var $gridList = $("#gridList");
    //    $gridList.jqGrid('setGridParam', {
    //        postData: { F_ClientId: F_ClientId },
    //    }).trigger('reloadGrid');
    //}

    //function gridList(F_ClientId) {
    //    var $gridList = $("#gridList");
    //    var queryJson = {};
    //    $gridList.dataGrid({
    //        url: "/ClientManager/DemandInfos/GetClientOrderHistoryList",
    //        postData: { F_ClientId: F_ClientId },
    //        height: 300,
    //        colModel: [
    //            { label: '公司名称', name: 'F_ClientName', align: 'left' },
    //            {
    //                label: '品牌项目组', name: 'F_ProjectName', align: 'left'
    //            },
    //            {
    //                label: '活动主题', name: 'F_ActivityTheme', align: 'left'
    //            },
    //            {
    //                label: '活动类型', name: 'F_ActivityType', align: 'left', formatter: function (cellvalue) {
    //                    return GetDictionaries(cellvalue, "F_ActivityType");
    //                }
    //            },
    //            { label: '预算金额(元)', name: 'F_DemandCash', align: 'left' },
    //            { label: '活动开始日期', name: 'F_ActivityStartDate', align: 'left' },
    //            {
    //                label: '活动结束日期', name: 'F_ActivityEndDate', align: 'left'
    //            },
    //            {
    //                label: '活动城市', name: 'F_ActivityCityId', align: 'left', formatter: function (cellvalue) {
    //                    return GetDictionaries(cellvalue, "F_ActivityCityId");
    //                }
    //            },
    //            { label: '联系人', name: 'F_Contact', align: 'left' },
    //            { label: '联系电话', name: 'F_Phone', align: 'left' },
    //            {
    //                label: '需求单状态', name: 'F_State', formatter: function (cellvalue) {
    //                    if (cellvalue == "0") {
    //                        return '草稿';
    //                    }
    //                    else if (cellvalue == "1") {
    //                        return '转订单';
    //                    }
    //                    else if (cellvalue == "2") {
    //                        return '无效需求';
    //                    }
    //                }
    //            },
    //            {
    //                label: '订单状态', name: 'orderState', formatter: function (cellvalue) {
    //                    if (cellvalue == "0") {
    //                        return '无效';
    //                    }
    //                    else if (cellvalue == "1") {
    //                        return '有效';
    //                    }
    //                }
    //            },
    //            { label: '需求创建时间', name: 'F_CreatorTime' },
    //            { label: '', name: 'F_Id', hidden: true }
    //        ],
    //        pager: "#gridPager",
    //        viewrecords: true,
    //        multiselect: false,
    //        sortname: 'F_Id',
    //        rowNum: 10,
    //        rowList: [10, 20, 30],
    //        ondblClickRow: function (rowid, iRow, iCol, e) {

    //        },
    //        loadComplete: function (data) {

    //        }
    //    });
    //}
    function GetDictionaries(value, type) {
        if (type == "F_ActivityCityId") {
            var strHtml = "";
            for (var i = 0; i < resultData.F_ActivityCityId.length; i++) {
                for (var j = 0; j < value.split(',').length; j++) {
                    if (j == value.split(',').length - 1) {
                        if (value.split(',')[j] == resultData.F_ActivityCityId[i].F_ItemCode) {
                            strHtml += resultData.F_ActivityCityId[i].F_ItemName;
                        }
                    } else {
                        if (value.split(',')[j] == resultData.F_ActivityCityId[i].F_ItemCode) {
                            strHtml += resultData.F_ActivityCityId[i].F_ItemName + ",";
                        }
                    }
                }
            }
            return strHtml;
        } else if (type == "F_ActivityType") {
            for (var i = 0; i < resultData.F_ActivityType.length; i++) {
                if (value == resultData.F_ActivityType[i].F_ItemCode) {
                    return resultData.F_ActivityType[i].F_ItemName;
                }
            }
            return '';
        }
    }

    function ProjectChange(f_fartherId) {
        var Projects = [];
        var siteProjects = resultData.Projects;
        for (var i = 0; i < siteProjects.length; i++) {
            if (siteProjects[i].F_ClientId == f_fartherId) {
                Projects.push({ value: siteProjects[i].F_ProjectName, data: siteProjects[i].F_Id });
            }
        }

        $("#F_ProjectId").autocomplete({
            lookup: Projects,
            onSelect: function (suggestion) {
                $("#hd_ProjectId").val(suggestion.data);
                ProjectInfo(suggestion.data);
            }
        });
    }

    var contracts;
    function ProjectInfo(projectId) {
        $.ajax({
            url: "/ClientManager/ClientInfos/GetProjectInfo?F_Id=" + projectId,
            dataType: "json",
            async: false,
            success: function (data) {
                contracts = data;
                if (data.length > 1) {
                    $("#contactArea").show();
                    $("#contactNum").html(data.length);
                    $("#contractList").empty();
                    for (var i = 0; i < data.length; i++) {
                        if (i == 0) {
                            $("#contractList").append("<li id=" + data[i]["F_Id"] + "><a style=\"cursor:pointer;\" onclick=\"ChangeContract(this)\" class=\"active\">" + data[i]["F_Contact"] + "</a></li>");
                            $("#F_Contact").val(data[i]["F_Contact"]);
                            $("#F_DepartmentId").val(data[i]["F_DepartmentId"]);
                            $("#F_PositionId").val(data[i]["F_PositionId"]);
                            $("#F_Phone").val(data[i]["F_Phone"]);
                            $("#F_Telephone").val(data[i]["F_Telephone"]);
                            $("#F_Mail").val(data[i]["F_Mail"]);
                            $("input[name='F_Sex'][value=" + data[i]["F_Sex"] + "]").attr("checked", true);
                        } else {
                            $("#contractList").append("<li id=" + data[i]["F_Id"] + "><a style=\"cursor:pointer;\" onclick=\"ChangeContract(this)\">" + data[i]["F_Contact"] + "</a></li>");
                        }
                    }
                } else {
                    $("#contactArea").hide();
                    $("#F_Contact").val(data[0]["F_Contact"]);
                    $("#F_DepartmentId").val(data[0]["F_DepartmentId"]);
                    $("#F_PositionId").val(data[0]["F_PositionId"]);
                    $("#F_Phone").val(data[0]["F_Phone"]);
                    $("#F_Telephone").val(data[0]["F_Telephone"]);
                    $("#F_Mail").val(data[0]["F_Mail"]);
                    $("input[name='F_Sex'][value=" + data[0]["F_Sex"] + "]").attr("checked", true);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) { }
        });
    }

    //function ChangeCityData() {
    //    var id = $("#F_CityId").val();
    //    $("#F_AreaId").empty();
    //    var F_AreaId = resultData.F_AreaId;
    //    for (var i = 0; i < F_AreaId.length; i++) {
    //        if (F_AreaId[i].F_ParentId == id) {
    //            $("#F_AreaId").append("<option value='" + F_AreaId[i].F_ItemCode + "'>" + F_AreaId[i].F_ItemName + "</option>");
    //        }
    //    }
    //}

    function GetInit() {
        $.ajax({
            url: "/WorkFlowSetting/FlowManage/GetDetailItemsJson",
            dataType: "json",
            async: false,
            success: function (data) {
                resultData = data;
                InitControl();
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }

    function ChangeClientType() {
        var F_ClientType = $("#F_ClientType").val();
        if (F_ClientType == "1") {
            $("#F_CompanyType").attr("disabled", "disabled");
            $("#F_CompanyType").css("background-color", "#ddd");
            $("#F_MappingId").attr("disabled", "disabled");
            $("#F_MappingId").css("background-color", "#ddd");

            $("#F_IndustryId").removeAttr("disabled");
            $("#F_IndustryId").css("background-color", "#fff");


        } else {
            $("#F_IndustryId").attr("disabled", "disabled");
            $("#F_IndustryId").css("background-color", "#ddd");

            $("#F_CompanyType").removeAttr("disabled");
            $("#F_CompanyType").css("background-color", "#fff");
            $("#F_MappingId").removeAttr("disabled");
            $("#F_MappingId").css("background-color", "#fff");
        }
    }

    function submitForm() {
        var F_CcUserIdList = $("#F_CcUserId").select2("data");
        var F_CcUserId = "";
        for (var i = 0; i < F_CcUserIdList.length; i++) {
            if (i == F_CcUserIdList.length - 1) {
                F_CcUserId += F_CcUserIdList[i].id;
            } else {
                F_CcUserId += F_CcUserIdList[i].id + ",";
            }
        }

        var F_OpreationUserIdList = $("#F_OpreationUserId").select2("data");
        var F_OpreationUserId = "";
        for (var i = 0; i < F_OpreationUserIdList.length; i++) {
            if (i == F_OpreationUserIdList.length - 1) {
                F_OpreationUserId += F_OpreationUserIdList[i].id;
            } else {
                F_OpreationUserId += F_OpreationUserIdList[i].id + ",";
            }
        }

        var F_MessageSendList = $("#F_MessageSend").select2("data");
        var F_MessageSend = "";
        for (var i = 0; i < F_MessageSendList.length; i++) {
            if (i == F_MessageSendList.length - 1) {
                F_MessageSend += F_MessageSendList[i].id;
            } else {
                F_MessageSend += F_MessageSendList[i].id + ",";
            }
        }

        var F_OpreationTypeList = $("#F_OpreationType").select2("data");
        var F_OpreationType = "";
        for (var i = 0; i < F_OpreationTypeList.length; i++) {
            if (i == F_OpreationTypeList.length - 1) {
                F_OpreationType += F_OpreationTypeList[i].id;
            } else {
                F_OpreationType += F_OpreationTypeList[i].id + ",";
            }
        }

        //if (!$('#form1').formValid()) {
        //    return false;
        //}

        //console.log($('#F_WorkFlowName').val());
        $.submitForm({
            url: "/WorkFlowSetting/FlowManage/SubmitForm?keyValue=" + keyValue,
            param: {
                'F_Id': keyValue,
                'F_WorkFlowId': workFlowId,
                'F_StepName': $('#F_StepName').val(),
                'F_TimeOutTip': $('#F_TimeOutTip').val(),
                'F_IsFishTime': $('#F_IsFishTime').val(),
                'F_WorkHours': $('#F_WorkHours').val(),
                'F_TimeOutOpreation': $('#F_TimeOutOpreation').val(),
                'F_OpreationType': F_OpreationType,
                'F_OpreationUserId': F_OpreationUserId,
                'F_OpreationStrategy': $('#F_OpreationStrategy').val(),
                'F_ReturnStrategy': $('#F_ReturnStrategy').val(),
                'F_ReturnType': $('#F_ReturnType').val(),
                'F_MessageSend': F_MessageSend,
                'F_CcUserId': F_CcUserId,
                'WorkFlowName': $.currentWindow().$('#F_WorkFlowName').val()
            },
            success: function () {

                $.currentWindow().$("#gridList").trigger("reloadGrid");
                //$.closeTab();
            }
        });
    }


</script>
<div id="ProjectsDetail">
    <form id="form1">
        <table class="form">
            <tr>
                <td colspan="6">
                    <table class="Table">
                        <tr>
                            <td class="formTitle">流程名称</td>
                            <td class="formValue">
                                <div class="input-group" style="width: 100%;">
                                    <input type="text" id="F_WorkFlowName" name="F_WorkFlowName" readonly class="form-control" placeholder="" />
                                </div>
                            </td>
                            <td class="formTitle">流程表单</td>
                            <td class="formValue">
                                <select id="F_WorkFormId" name="F_WorkFormId" readonly class="form-control required" onchange=""></select>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="6">
                    <table class="Table">
                        <tr>
                            <td class="formTitle">创建人</td>
                            <td class="formValue">
                                <div class="input-group" style="width: 100%;">
                                    <input type="text" id="F_CreatorUserId" name="F_CreatorUserId" readonly class="form-control" placeholder="" />
                                </div>
                            </td>
                            <td class="formTitle">创建时间</td>
                            <td class="formValue">
                                <div class="input-group" style="width: 100%;">
                                    <input type="text" id="F_CreatorTime" name="F_CreatorTime" readonly class="form-control" placeholder="" />
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="6">
                    <table class="Table">
                        <tr>
                            <td class="formTitle">修改人</td>
                            <td class="formValue">
                                <div class="input-group" style="width: 100%;">
                                    <input type="text" id="F_LastModifyUserId" name="F_LastModifyUserId" readonly class="form-control" placeholder="" />
                                </div>
                            </td>
                            <td class="formTitle">修改时间</td>
                            <td class="formValue">
                                <div class="input-group" style="width: 100%;">
                                    <input type="text" id="F_LastModifyTime" name="F_LastModifyTime" readonly class="form-control" placeholder="" />
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>
